package cn.pfz.domain;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: 普发忠
 * @Date: 2021/10/08/10:12
 */
@Data
@TableName("region")
public class Region extends BaseDomain {
    
    public static final int STATE_HOT=1;
    public static final int STATE_NORMAL=0;
    
    private String name;
    private String sn;
    
    private String refIds;//关联目的地 以逗号隔开
    private Integer ishot=STATE_NORMAL;
    private Integer seq;
    private String info;
    
    
    public String getJsonString (){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",super.getId());
        map.put("name",this.getName());
        map.put("sn",this.getSn());
        map.put("refIds",this.getRefIds());
        map.put("ishot",this.getIshot());
        map.put("seq",this.getSeq());
        map.put("info",this.getInfo());
        return JSON.toJSONString(map);
    }
    
    //拆解关联地点
    public List<Long> parseRefIds() {
        ArrayList<Long> ids = new ArrayList<>();
        if (StringUtils.isNotBlank(refIds)){
            String[] split = refIds.split(",");
            if (split!=null&&split.length > 0){
                for (int i = 0; i < split.length; i++) {
                    ids.add(Long.parseLong(split[i]));
                }
            }
        }
        return ids;
    }
}
